package cn.liangxxhu.rocketmq.core.strategy;

import cn.liangxxhu.rocketmq.enums.MessageTypeEnum;
import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.Message;

@RequiredArgsConstructor
/**
 * 延迟消息发送策略：使用 RocketMQTemplate 的秒级延迟发送能力。
 */
public class DelayMessageStrategy implements MessageSendStrategy {

    private final RocketMQTemplate rocketMQTemplate;

    @Override
    public SendResult send(String destination, Message<?> message, long timeout, long delayTime) {
        return rocketMQTemplate.syncSendDelayTimeSeconds(destination, message, delayTime);
    }

    @Override
    public String getMessageType() {
        return MessageTypeEnum.DELAY.getCode();
    }
}
